package com.example.weizix.ui.adapter;

import android.content.Context;
import android.support.v7.widget.SwitchCompat;
import android.widget.CompoundButton;

import com.example.weizix.R;
import com.example.weizix.base.BaseRlAdapter;
import com.example.weizix.bean.DataBean;

import java.util.ArrayList;
import java.util.List;

public class RlvInterestAdapter extends BaseRlAdapter<DataBean> {

    public RlvInterestAdapter(Context context, List<DataBean> list) {
        super(context, (ArrayList<DataBean>) list);
    }

    @Override
    protected void bindData(BaseViewHolder holder, final DataBean dataBean) {
        holder.setText(R.id.tv,dataBean.getName());
        SwitchCompat sc = (SwitchCompat) holder.findVIew(R.id.sc);
        sc.setChecked(dataBean.isSelect());

        sc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                //用户是否按控件
                if (buttonView.isPressed()){
                    dataBean.setSelect(isChecked);
                }
            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.item_interest;
    }
}

